package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.Province;
import com.ktgj.flight.service.IProvinceService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 省份Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/province")
public class ProvinceController extends BaseController
{
    @Autowired
    private IProvinceService provinceService;

    /**
     * 查询省份列表
     */
    @PreAuthorize(hasPermi = "flight:province:list")
    @GetMapping("/list")
    public TableDataInfo list(Province province)
    {
        startPage();
        List<Province> list = provinceService.selectProvinceList(province);
        return getDataTable(list);
    }

    /**
     * 导出省份列表
     */
    @PreAuthorize(hasPermi = "flight:province:export")
    @Log(title = "省份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Province province) throws IOException
    {
        List<Province> list = provinceService.selectProvinceList(province);
        ExcelUtil<Province> util = new ExcelUtil<Province>(Province.class);
        util.exportExcel(response, list, "省份数据");
    }

    /**
     * 获取省份详细信息
     */
    @PreAuthorize(hasPermi = "flight:province:query")
    @GetMapping(value = "/{provinceId}")
    public AjaxResult getInfo(@PathVariable("provinceId") Long provinceId)
    {
        return AjaxResult.success(provinceService.selectProvinceById(provinceId));
    }

    /**
     * 新增省份
     */
    @PreAuthorize(hasPermi = "flight:province:add")
    @Log(title = "省份", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Province province)
    {
        return toAjax(provinceService.insertProvince(province));
    }

    /**
     * 修改省份
     */
    @PreAuthorize(hasPermi = "flight:province:edit")
    @Log(title = "省份", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Province province)
    {
        return toAjax(provinceService.updateProvince(province));
    }

    /**
     * 删除省份
     */
    @PreAuthorize(hasPermi = "flight:province:remove")
    @Log(title = "省份", businessType = BusinessType.DELETE)
	@DeleteMapping("/{provinceIds}")
    public AjaxResult remove(@PathVariable Long[] provinceIds)
    {
        return toAjax(provinceService.deleteProvinceByIds(provinceIds));
    }
}
